require 'higher.rb'

module Enumerable
	# Iterators 1
	def each_even
		each do |number|
			if number%2==0 then
				yield number
			end
		end
	end

	# Iterators 2
	def each_grouped_by_first_letter
		grouped_by_first_letter = group_by {|x| x[0,1].to_s}
		grouped_by_first_letter.each {|letter,items| yield letter, items}
	end
end

a = %w(apple banana cherry alice bob carol alpha bravo charlie)  # %w is shorthand for an array of strings
a.each_grouped_by_first_letter do |letter, words|
	puts "#{letter} : #{words.join(' ')}"
end